package cn.disignPattern.com.partTwo;


import java.util.Observable;

/**
 * Created by Administrator on 2021/6/22 0022.
 */
public class CurrentConditionDisply2 implements java.util.Observer,DisplayElement {

    private float temp;
    private float humidity;
    private Observable weatherData;

    public CurrentConditionDisply2(Observable weatherData) {
        this.weatherData = weatherData;
        weatherData.addObserver(this);
    }

    @Override
    public void display() {
        System.out.println( "CurrentConditionDisply{" +
                "temp=" + temp +
                ", humidity=" + humidity +
                ", weatherData=" + weatherData +
                '}');
    }

    @Override
    public void update(Observable o, Object arg) {
        if(o instanceof WeatherData2){
            WeatherData2 weatherData2 = (WeatherData2) o;
            this.temp = weatherData2.getTemp();
            this.humidity = weatherData2.getHumidity();
            display();
        }
    }
}